graph drop _all
********************
*** FIGURE B1 ***
********************
*** HAMBURG ESSO PRICE CHANGES

use "$P_Data/PCCount/daily_weekday_nonholiday-7to21-positive_price_only_e5.dta", clear

keep if StID==2154
tostring YMD, replace
gener date = date(YMD,"YMD")
gener month = month(date)
gener year = year(date)
drop YMD
rename date YMD

drop if year<2016
drop if year>2018

merge m:1 StID using "$P_Data/GS/gas_station.dta"
keep if _merge==3
drop _merge

gener week = week(YMD)

gener weekly_date = yw(year,week)

gegen mean_PCCount = mean(PCCount), by(weekly_date StID)

fsort StID weekly_date YMD
by StID weekly_date: keep if _n==1

* merging break date 
merge m:1 StID using "$P_Data_Processed/pccount_breaks_e5.dta"
keep if _merge==3
drop _merge

sort weekly_date
format weekly_date %tw 

tw (line mean_PCCount weekly_date), tline(2982) ytitle("N Price Changes") xtitle("Week") note("vertical line = QLR best candidate break date") title("Hamburg Esso - N Price Changes") name(b1_a)
gr export "$P_Figures/Figure_B1_a.eps", replace 

***** 

*** HAMBURG ESSO RIVAL RESPONSE TIME 


use "$P_Data/PCResponse/rival_diffbrand_daily_weekday_nonholiday_e5.dta", clear 

keep if StID==2154
tostring YMD, replace
gener date = date(YMD,"YMD")
gener month = month(date)
gener year = year(date)
drop YMD
rename date YMD

drop if year<2016
drop if year>2018

merge m:1 StID using "$P_Data/GS/gas_station.dta"
keep if _merge==3
drop _merge

gener week = week(YMD)

gener weekly_date = yw(year,week)

gegen mean_Response = mean(Response), by(weekly_date StID)

fsort StID weekly_date YMD
by StID weekly_date: keep if _n==1

* merging break date 
merge m:1 StID using "$P_Data_Processed/pcresponse_breaks_e5.dta"
keep if _merge==3
drop _merge

sort weekly_date
format weekly_date %tw 

tw (line mean_Response weekly_date), tline(2978) ytitle("Response Time to Nearest Rival, Minutes") xtitle("Week") note("vertical line = QLR best candidate break date") title("Hamburg Esso - Response Time to Rival") name(b1_b)
gr export "$P_Figures/Figure_B1_b.eps", replace 


 
graph combine b1_a b1_b, iscale(1) xsize(10)

gr export "$P_Figures/Figure_B1.eps", replace 


********************
*** FIGURE B2 ***
********************

*** AALEN ARAL PRICE CHANGES

use "$P_Data/PCCount/daily_weekday_nonholiday-7to21-positive_price_only_e5.dta", clear

keep if StID==9975
tostring YMD, replace
gener date = date(YMD,"YMD")
gener month = month(date)
gener year = year(date)
drop YMD
rename date YMD

drop if year<2016
drop if year>2018

merge m:1 StID using "$P_Data/GS/gas_station.dta"
keep if _merge==3
drop _merge

gener week = week(YMD)

gener weekly_date = yw(year,week)

gegen mean_PCCount = mean(PCCount), by(weekly_date StID)

fsort StID weekly_date YMD
by StID weekly_date: keep if _n==1

sort weekly_date
format weekly_date %tw 

tsset weekly_date
tsfill 

capture drop missing
gener missing = (mean_PCCount==.)*20

gener weekly_date_m = weekly_date if missing==20 


tw (line mean_PCCount weekly_date, cmissing(n)) (area missing weekly_date_m),  ytitle("N Price Changes") xtitle("Week") title("Aalen Aral - N Price Changes") legend(off) name(b2_a)
gr export "$P_Figures/Figure_B2_a.eps", replace 


*** AALEN ARAL RIVAL RESPONSE TIME 


use "$P_Data/PCResponse/rival_diffbrand_daily_weekday_nonholiday_e5.dta", clear 

keep if StID==9975
tostring YMD, replace
gener date = date(YMD,"YMD")
gener month = month(date)
gener year = year(date)
drop YMD
rename date YMD

drop if year<2016
drop if year>2018

merge m:1 StID using "$P_Data/GS/gas_station.dta"
keep if _merge==3
drop _merge

gener week = week(YMD)

gener weekly_date = yw(year,week)

gegen mean_Response = mean(Response), by(weekly_date StID)

fsort StID weekly_date YMD
by StID weekly_date: keep if _n==1

sort weekly_date
format weekly_date %tw 


tsset weekly_date
tsfill 

capture drop missing
gener missing = (mean_Response==.)*200

gener weekly_date_m = weekly_date if missing==200 

tw (line mean_Response weekly_date, cmissing(n))  (area missing weekly_date_m),  ytitle("Response Time to Nearest Rival, Minutes") xtitle("Week") title("Aalen Aral - Response Time to Rival") legend(off) name(b2_b)
gr export "$P_Figures/Figure_B2_b.eps", replace 


graph combine b2_a b2_b, iscale(1) xsize(10)

gr export "$P_Figures/Figure_B2.eps", replace 

